using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using CheckedComboBox;
using ZoneFiveSoftware.Common.Data.Fitness;

namespace FilteredStatistics.View
{
    class ZoneCategoriesDataGridViewEditingControl : CheckedComboBoxControl, IDataGridViewEditingControl
    {
        public ZoneCategoriesDataGridViewEditingControl()
        {
        }

#region IDataGridViewEditingControl Members
        public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
        {
            Font = dataGridViewCellStyle.Font;
            ForeColor = dataGridViewCellStyle.ForeColor;
            BackColor = dataGridViewCellStyle.BackColor;
        }

        public DataGridView EditingControlDataGridView
        {
            get { return m_ParentDataGrid; }
            set { m_ParentDataGrid = value; }
        }

        public object EditingControlFormattedValue
        {
            get { return base.CheckedItemsStringValue; }
            set { }
        }

        public int EditingControlRowIndex
        {
            get { return m_RowIndex; }
            set { m_RowIndex = value; }
        }

        public bool EditingControlValueChanged
        {
            get { return m_ValueChanged; }
            set { m_ValueChanged = value; }
        }

        public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
        {
            return false;
        }

        public Cursor EditingPanelCursor
        {
            get { return Cursors.Default; }
        }

        public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
        {
            return EditingControlFormattedValue;
        }

        public void PrepareEditingControlForEdit(bool selectAll)
        {
            ZoneCategoriesDataGridViewCell holdingCell = m_ParentDataGrid.CurrentCell as ZoneCategoriesDataGridViewCell;
            DataGridViewComboBoxCell zoneTypeCell = m_ParentDataGrid.Rows[holdingCell.RowIndex].Cells[holdingCell.ColumnIndex - 1] as DataGridViewComboBoxCell;

            Debug.Assert(holdingCell != null && zoneTypeCell != null);

            Enabled = zoneTypeCell.Value != null;

            if (Enabled)
            {
                ShowDropDown();
            }
        }

        public bool RepositionEditingControlOnValueChange
        {
            get { return false; }
        }
#endregion

        DataGridView m_ParentDataGrid;
        int m_RowIndex;
        bool m_ValueChanged;
    }
}
